package com.shuai.tool;

import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

import com.shuai.stickynote.R;
import com.shuai.ui.MyRemoteViews;

public class SendTool {
    public static final String WIDGET_ACTION_TEXT = "TextWidget";
    public static final String WIDGET_ACTION_PLANT = "PlantWidget";
    public static final String WIDGET_ACTION_TASK = "TaskWidget";
    public static final String WIDGET_ACTION_MENORY = "MenoryWidget";
    public static final String TYPE_TEXT = "text";
    public static final String TYPE_PLANT = "plant";
    public static final String TYPE_TASK = "task";
    public static final String TYPE_MEMORY = "memory";
    public static final String TYPE = "type";
    public static final String NOTE_ID = "noteId";

    public static void sendToWidget(Context context, Class widgetClass, int widgetID, String action,
                                    String noteId, String type){
        Intent intent = new Intent(context, widgetClass);
        intent.setAction(action);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,widgetID);
        intent.putExtra(NOTE_ID,noteId);
        intent.putExtra(TYPE,type);
        context.sendBroadcast(intent);
    }

    public static class RemoteViewsFactory {
        public static RemoteViews getRemoteViews(Context context, String type){
            RemoteViews views = null;
            switch (type){
                case TYPE_TEXT:
                    views = new MyRemoteViews(context.getPackageName(), R.layout.widget_text);
                    break;
                case TYPE_TASK:
                    views = new MyRemoteViews(context.getPackageName(), R.layout.widget_plant);
                    break;
                case TYPE_PLANT:
                    views = new MyRemoteViews(context.getPackageName(), R.layout.plant_widget);
                    break;
                case TYPE_MEMORY:
                    views = new MyRemoteViews(context.getPackageName(), R.layout.memory_widget);
                    break;
                default:
                    views = new MyRemoteViews(context.getPackageName(), R.layout.default_widget);
                    break;
            }
            return views;
        }
    }
}
